home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / VPOJAVA.DLL / SOURCE / DIALOG < prev    next >
Text File  |  1998-12-10  |  3KB  |  105 lines

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6.  
  7. public class Dialog1 extends Dialog
  8. {
  9.     public Dialog1(Frame parent)
  10.     {
  11.         super(parent);
  12.  
  13.         // This code is automatically generated by Visual Cafe when you add
  14.         // components to the visual environment. It instantiates and initializes
  15.         // the components. To modify the code, only use code syntax that matches
  16.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  17.         // parse your Java file into its visual environment.
  18.         //{{INIT_CONTROLS
  19.         setLayout(null);
  20.         setSize(430,270);
  21.         setTitle("");
  22.         //}}
  23.  
  24.         //{{REGISTER_LISTENERS
  25.         SymWindow aSymWindow = new SymWindow();
  26.         this.addWindowListener(aSymWindow);
  27.         //}}
  28.     }
  29.     
  30.     public Dialog1(Frame parent, boolean modal)
  31.     {
  32.         this(parent);
  33.         setModal(modal);
  34.     }
  35.     
  36.     public void addNotify()
  37.     {
  38.           // Record the size of the window prior to calling parents addNotify.
  39.         Dimension d = getSize();
  40.  
  41.         super.addNotify();
  42.  
  43.         if (fComponentsAdjusted)
  44.             return;
  45.  
  46.         // Adjust components according to the insets
  47.         Insets insets = getInsets();
  48.         setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
  49.         Component components[] = getComponents();
  50.         for (int i = 0; i < components.length; i++)
  51.         {
  52.             Point p = components[i].getLocation();
  53.             p.translate(insets.left, insets.top);
  54.             components[i].setLocation(p);
  55.         }
  56.         fComponentsAdjusted = true;
  57.     }
  58.  
  59.     // Used for addNotify check.
  60.     boolean fComponentsAdjusted = false;
  61.  
  62.  
  63.     public Dialog1(Frame parent, String title, boolean modal)
  64.     {
  65.         this(parent, modal);
  66.         setTitle(title);
  67.     }
  68.  
  69.     /**
  70.      * Shows or hides the component depending on the boolean flag b.
  71.      * @param b  if true, show the component; otherwise, hide the component.
  72.      * @see java.awt.Component#isVisible
  73.      */
  74.     public void setVisible(boolean b)
  75.     {
  76.         if(b)
  77.         {
  78.             Rectangle bounds = getParent().getBounds();
  79.             Rectangle abounds = getBounds();
  80.     
  81.             setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
  82.                  bounds.y + (bounds.height - abounds.height)/2);
  83.         }
  84.         super.setVisible(b);
  85.     }
  86.  
  87.     //{{DECLARE_CONTROLS
  88.     //}}
  89.  
  90.     class SymWindow extends java.awt.event.WindowAdapter
  91.     {
  92.         public void windowClosing(java.awt.event.WindowEvent event)
  93.         {
  94.             Object object = event.getSource();
  95.             if (object == Dialog1.this)
  96.                 Dialog1_WindowClosing(event);
  97.         }
  98.     }
  99.     
  100.     void Dialog1_WindowClosing(java.awt.event.WindowEvent event)
  101.     {
  102.         setVisible(false);
  103.     }
  104. }
  105.